function [ allCarsMatrix ] = ReadAllCars
%READALLCARS Summary of this function goes here
%   Creat Matrix with All Cars, Features from external Function and Set the
%   label to 1 (Cars).
% Labels1 : 1 for Cars, 2 for Sport2, 3 for SUVs and 4 for Trucks
% Labels2 : 10 for Back pose, 11 for Side pose and 12 for Front pose

%javaaddpath('C:\Program Files (x86)\Weka-3-7\weka.jar')
clear
load('vehicles_shortest.mat');
javaaddpath('C:\Program Files\Weka-3-6\weka.jar')


allCarsMatrix = zeros(1008,257);
 % First 252 images are for     Truck     , Label 1
 allCarsMatrix(1:252,257) = -1;
 % Second 252 images are for    Cars  , Label 2
allCarsMatrix(253:504,257) = -2;
% Third 252 images are for      SUV's   , Label 3
allCarsMatrix(505:756,257) = -3;
% Fourth 252 images are for     Sports  , Label 4
allCarsMatrix(757:1008,257) = -4;
%intImageNumber=1;
%class = cell(1008,1);
%i= 1;
%while(i < 1009)
%%    class(i:i+2,1) = {'10'};
%    class(i+3:i+5,1) = {'11'};
%    class(i+6:i+8,1) = {'12'};
%    i = i +9 ;
%end    

for i=1:1008
    
    for k=1:127
      allCarsMatrix(i,k+2) =vehicles(i).selected_hog_features(k); 
      allCarsMatrix(i,k+129) =(vehicles(i).selected_wave_features(k)');
    end     
end
 
%for i=1:1008
    %allCarsMatrix(i,2) = i ;
   %allCarsMatrix(i,5:132)= vehicles(i).selected_hog_features;
            
%en
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
load('selected_obj.mat');

testingMatrix = [];
traingingMatrix = [];
lable =[];
class_label = [];
total_guess = [];
predection = [];
allAttr={};
types={};
for i=1:127
   allAttr = [allAttr {strcat('hog',num2str(i))}];
   types = [types {'numeric'}];
end
for i=1:127
   allAttr = [allAttr {strcat('wavlet',num2str(i))}];
   types = [types {'numeric'}];
end
      
   allAttr = [allAttr {'class'}];
   types = [types {'f s b'}];
   
c = 1;
while(c < 11)
    if(c==1)
       testing = allCarsMatrix(1:100,3:257);
       label = horzcat(lable, allCarsMatrix(1:100,257));
       training = allCarsMatrix(101:999,3:257);
      
       
    else
       testing = allCarsMatrix((c-1)*100+1:(c)*100,3:257);
       label = horzcat(lable, allCarsMatrix((c-1)*100+1:(c)*100,257));
       training = allCarsMatrix(1:(c-1)*100,3:257);
       training = vertcat(training,(allCarsMatrix((c*100)+1:999,3:257)));
       %training2 =allCarsMatrix((c*100)+1:1008,3:257);
    end
     
     %label = label';
     class_label = [class_label label];
     label= [];
     trainingfile = strcat('typetraining', num2str(c),'.arff');
     testingfile = strcat('typetesting' , num2str(c),'.arff');
     %create and save training data set
     wekaobj = matlab2weka('training',allAttr,training);
     %saveARFF(trainingfile,wekaobj);
     %create and save testing data set
     wekaobj2 = matlab2weka('testing',allAttr,testing);
     %saveARFF(testingfile,wekaobj2);
     c=c+1;
     disp('I am here!')
end
     %load arff file.
     for k=1:10
        training = loadARFF(strcat('typetraining',num2str(k),'-fixed.arff'));
        testing = loadARFF(strcat('typetesting',num2str(k),'-fixed.arff'));
        model = trainWekaClassifier(training,'functions.SMO','-C 100.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K "weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0"');
        [predictedClass, classProbs] = wekaClassify(testing,model);
        predection  = horzcat(predection, predictedClass);
        correct_guess = 0;
        for i=1:100
            if(class_label(i,1) ==  -(predection(i,1)+1))
                 correct_guess = correct_guess+1;
            end
        end
        total_guess = horzcat(total_guess,correct_guess);
        correct_guess = 0;
        disp('testingMatrix')
     end
     
    display(correct_guess)

disp('testingMatrix')
%testingMatrix =  allCarsMatrix;
    
end
   
           
